'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.graph.Node_Concrete import Node_Concrete
from base.rdf.impl.Util import Util

#import org.apache.jena.rdf.model.impl.Util;
#import org.apache.jena.shared.*;

'''
 * RDF nodes with a global identity given by a URI.
'''
class Node_URI(Node_Concrete):

    # protected Node_URI(String uri):
    #     super().__init__(uri)
    def __init__(self, uri):
        super().__init__(uri)

    #@Override
    # param 
    # result String
    def getURI(self):
        return self.label
    

    #@Override
    # param NodeVisitor v
    # result Object
    def visitWith(self, v):
        return v.visitURI(self, self.label)
    

    #@Override
    # param 
    # result boolean
    def isURI(self):
        return True
    

    '''
     * Answer a String representing the node, taking into account the PrefixMapping.
     * The horrible test against null is a stopgap to avoid a circularity issue.
     * TODO fix the circularity issue
    '''
    #@Override
    # param PrefixMapping pm, boolean quoting
    # result String
    def toString(self, pm, quoting):
        #return (String) label if pm is None else pm.shortForm((String) label)
        return str(self.label) if pm is None else pm.shortForm(str(self.label))
    

    #@Override
    # param Object other
    # result boolean
    def equals(self, other):
        if (self == other):
            return True
        return isinstance(other, Node_URI) and self.same(other)
                # other instanceof Node_URI
                #         and same((Node_URI) other)
    

    # param Node_URI
    # return
    def same(self, other):
        return self.label.equals(other.label)
    

    #@Override
    # param 
    # result String
    def getNameSpace(self):
        #String s = (String) label
        return self.label.substring(0, Util.splitNamespaceXML(self.label))
    

    #@Override
    # param 
    # result String
    def getLocalName(self):
        #String s = (String) label
        return self.label.substring(Util.splitNamespaceXML(self.label))
    

    #@Override
    # param String uri
    # result boolean
    def hasURI(self, uri):
        return self.label.equals(uri)
    



